package com.gitee.wsl.compose.modifier

import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.CacheDrawScope
import androidx.compose.ui.draw.DrawResult
import androidx.compose.ui.draw.drawBehind
import androidx.compose.ui.draw.drawWithCache
import androidx.compose.ui.draw.drawWithContent
import androidx.compose.ui.graphics.drawscope.ContentDrawScope
import androidx.compose.ui.graphics.drawscope.DrawScope

interface ModifierDrawScope: ModifierScope {
    fun drawWithCache(onBuildDrawCache: CacheDrawScope.() -> DrawResult){
        modifier = modifier.drawWithCache(onBuildDrawCache)
    }

    fun drawWithContent(onDraw: ContentDrawScope.() -> Unit){
        modifier = modifier.drawWithContent(onDraw)
    }

    fun drawBehind(onDraw: DrawScope.() -> Unit){
        modifier = modifier.drawBehind(onDraw)
    }
}

class ModifierDrawScopeImp(override var modifier: Modifier): ModifierDrawScope

fun Modifier.draw(block: ModifierDrawScope.()->Unit) = ModifierDrawScopeImp(this).apply(block).modifier